'use strict';
function grouping_digit(collection){
    let collection_a=[];
    for(let i in collection){
        let num1=collection[i];
        let num2;
        for(let j=0;;j++){
            num2=num1%10;
            num1=Math.floor(num1/10);
            if(num1==0){
                if(collection_a[j]==undefined||collection_a[j]==null){
                    collection_a[j]=[];
                }
                collection_a[j].push(collection[i]);
                break;
            }
        }
    }
    for(let i=0;i<collection_a.length;i++){
        if(collection_a[i]==undefined||collection_a[i]==null||collection_a[i]==0){
            collection_a.splice(i,1);
            i=i-1;
        }
    }
    console.log(collection_a);
    return collection_a;
}
var even_group_calculate_average = function(collection){
    let even_collection=[];
    for(let i in collection){
        if(i%2!=0){
            even_collection.push(collection[i]); 
        }
    }
    even_collection=even_collection.filter(function(item){
        return (item%2==0);
    });
    even_collection=grouping_digit(even_collection);

    for(let i in even_collection){
        let sum=0;
        for(let j in even_collection[i]){
            sum+=even_collection[i][j];
        }
        even_collection[i]=sum/even_collection[i].length;
    }
    if(even_collection.length==0){
        even_collection=[0];
    }
    console.log(even_collection);
    return even_collection;

}
module.exports = even_group_calculate_average;
even_group_calculate_average([344, 256, 55, 777, 322, 180]);
